#include "precomp.h"
#include "HUD.h"

	HUD::HUD(Player *player, CL_GraphicContext *gc, CL_Pointf position, float padding_left, int font_size)
		: _player(player), HUD_Object(gc)
	{
		this->set_position(position.x + padding_left, position.y);

		_life = new HUD_Object(gc);
		_life->set_position(5, 0);
		_life->set_image(HEART_DIR, CL_Pointf(0, 0));
		_life->set_font(cl_format("%1", _player->get_hp()), font_size, CL_Pointf(48 + 3, font_size), CL_Colord::red);

		_gun = new HUD_Object(gc);
		_gun->set_position(640 - 250, 0);
		_gun->set_image(HANDGUN_DIR, CL_Pointf(0,0));
		_gun->set_font(cl_format("%1/%2", _player->get_bullets(), _player->get_clips()), font_size, CL_Pointf(64, font_size));

		this->add(_life);
		this->add(_gun);

		_pre_gun_number = HAND_GUN;
	}

	HUD::~HUD(){
		delete _life, _gun;
	}

	void HUD::tick(float delta_time){
		_life->change_text(cl_format("%1", _player->get_hp()));

		_gun->change_text(cl_format("%1/%2", _player->get_bullets(), _player->get_clips()));

		if(_pre_gun_number != _player->get_gun_number()){
			const char *gun_dir;
			switch(_player->get_gun_number()){
				case HAND_GUN:
					gun_dir = HANDGUN_DIR;
					break;

				case M4A1:
					gun_dir = M4A1_DIR;
					break;

				default:
					gun_dir = HANDGUN_DIR;
			}
			_gun->change_image(gun_dir);

			_pre_gun_number = _player->get_gun_number();
		}
	}